package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.MaintenanceConfig;
import com.sailfish.springbootdemo.service.db1.MaintenanceConfigService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/maintenanceConfig")
public class MaintenanceConfigController {

    @Autowired
    private MaintenanceConfigService maintenanceConfigService;

    @PostMapping("/getMaintenanceConfigByType")
    public Result getMaintenanceConfigByType(Integer maintenanceConfigType) {
        try {
            if (maintenanceConfigType == null || "".equals(maintenanceConfigType.toString())) {
                return ResultUtil.error(500, "缺少参数maintenanceConfigType", "Miss Param maintenanceConfigType", null);
            }
            return ResultUtil.success(maintenanceConfigService.getMaintenanceConfigByType(maintenanceConfigType));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/updateMaintenanceConfig")
    public Result updateMaintenanceConfig(MaintenanceConfig maintenanceConfig) {
        return maintenanceConfigService.updateMaintenanceConfig(maintenanceConfig);
    }

    @PostMapping("/updateSendEmailUsers")
    public Result updateSendEmailUsers(Integer maintenanceConfigId, String sendEmailUsers) {
        return maintenanceConfigService.updateSendEmailUsers(maintenanceConfigId, sendEmailUsers);
    }
}
